package org.jeecg.modules.cascv.image.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.modules.cascv.image.entity.GdqvXml;
import org.jeecg.modules.cascv.image.service.IGdqvXmlService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.system.base.controller.JeecgController;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

 /**
 * @Description: xml表
 * @Author: jeecg-boot
 * @Date:   2022-08-30
 * @Version: V1.0
 */
@Slf4j
@Api(tags="xml表")
@RestController
@RequestMapping("/test/gdqvXml")
public class GdqvXmlController extends JeecgController<GdqvXml, IGdqvXmlService> {
	@Autowired
	private IGdqvXmlService gdqvXmlService;
	
	/**
	 * 分页列表查询
	 *
	 * @param gdqvXml
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@AutoLog(value = "xml表-分页列表查询")
	@ApiOperation(value="xml表-分页列表查询", notes="xml表-分页列表查询")
	@GetMapping(value = "/list")
	public Result<?> queryPageList(GdqvXml gdqvXml,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<GdqvXml> queryWrapper = QueryGenerator.initQueryWrapper(gdqvXml, req.getParameterMap());
		queryWrapper.eq("del_flag", CommonConstant.DEL_FLAG_0);
		Page<GdqvXml> page = new Page<GdqvXml>(pageNo, pageSize);
		IPage<GdqvXml> pageList = gdqvXmlService.page(page, queryWrapper);
		return Result.OK(pageList);
	}

	 /**
	  * 分页列表查询
	  *
	  * @param gdqvXml
	  * @param req
	  * @return
	  */
	 @AutoLog(value = "xml表-分页列表查询")
	 @ApiOperation(value="xml表-分页列表查询", notes="xml表-分页列表查询")
	 @GetMapping(value = "/listAll")
	 public Result<?> queryList(GdqvXml gdqvXml,
									HttpServletRequest req) {
		 QueryWrapper<GdqvXml> queryWrapper = QueryGenerator.initQueryWrapper(gdqvXml, req.getParameterMap());
		 queryWrapper.eq("del_flag", CommonConstant.DEL_FLAG_0);
		 List<GdqvXml> pageList = gdqvXmlService.list(queryWrapper);
		 for (GdqvXml xml : pageList) {
			 xml.setXmlName(xml.getXmlName() + "(" + xml.getEquipmentname() + ")");
		 }
		 return Result.OK(pageList);
	 }

	/**
	 * 添加
	 *
	 * @param gdqvXml
	 * @return
	 */
	@AutoLog(value = "xml表-添加")
	@ApiOperation(value="xml表-添加", notes="xml表-添加")
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody GdqvXml gdqvXml) {
		gdqvXmlService.save(gdqvXml);
		return Result.OK("添加成功！");
	}
	
	/**
	 * 编辑
	 *
	 * @param gdqvXml
	 * @return
	 */
	@AutoLog(value = "xml表-编辑")
	@ApiOperation(value="xml表-编辑", notes="xml表-编辑")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<?> edit(@RequestBody GdqvXml gdqvXml) {
		gdqvXmlService.updateById(gdqvXml);
		return Result.OK("编辑成功!");
	}
	
	/**
	 * 通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "xml表-通过id删除")
	@ApiOperation(value="xml表-通过id删除", notes="xml表-通过id删除")
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
		gdqvXmlService.removeById(id);
		return Result.OK("删除成功!");
	}
	
	/**
	 * 批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "xml表-批量删除")
	@ApiOperation(value="xml表-批量删除", notes="xml表-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.gdqvXmlService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功！");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "xml表-通过id查询")
	@ApiOperation(value="xml表-通过id查询", notes="xml表-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
		GdqvXml gdqvXml = gdqvXmlService.getById(id);
		return Result.OK(gdqvXml);
	}

  /**
   * 导出excel
   *
   * @param request
   * @param gdqvXml
   */
  @RequestMapping(value = "/exportXls")
  public ModelAndView exportXls(HttpServletRequest request, GdqvXml gdqvXml) {
      return super.exportXls(request, gdqvXml, GdqvXml.class, "xml表");
  }

  /**
   * 通过excel导入数据
   *
   * @param request
   * @param response
   * @return
   */
  @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
  public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
      return super.importExcel(request, response, GdqvXml.class);
  }

}
